/**
 * 名称：Flags编辑页面
 */
import 'package:flutter/material.dart';
import 'package:flutter_todo_2019/page/utils/date_util.dart';

class FlagsDetailPage extends StatefulWidget {
  FlagsDetailPage({Key key, this.title}) : super(key: key);

  // This widget is the home page of your application. It is stateful, meaning
  // that it has a State object (defined below) that contains fields that affect
  // how it looks.

  // This class is the configuration for the state. It holds the values (in this
  // case the title) provided by the parent (in this case the App widget) and
  // used by the build method of the State. Fields in a Widget subclass are
  // always marked "final".

  final String title;

  @override
  _FlagsDetailPageState createState() => _FlagsDetailPageState();
}

class _FlagsDetailPageState extends State<FlagsDetailPage> {
  String radio = "0";
  String time = "";

  void _incrementCounter() {
    setState(() {
      // This call to setState tells the Flutter framework that something has
      // changed in this State, which causes it to rerun the build method below
      // so that the display can reflect the updated values. If we changed
      // _counter without calling setState(), then the build method would not be
      // called again, and so nothing would appear to happen.
    });
  }

  @override
  Widget build(BuildContext context) {
    // This method is rerun every time setState is called, for instance as done
    // by the _incrementCounter method above.
    //
    // The Flutter framework has been optimized to make rerunning build methods
    // fast, so that you can just rebuild anything that needs updating rather
    // than having to individually change instances of widgets.
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        leading: new IconButton(
            icon: const Icon(Icons.arrow_back, color: Colors.white),
            onPressed: () => Navigator.pop(context)),
        title: Text(widget.title,style: TextStyle(color: Colors.white,fontSize: 16),),
        centerTitle: true,
      ),
      body: Column(
        children: <Widget>[
          Container(
            margin: const EdgeInsets.fromLTRB(0, 5, 0, 0),
          ),
          Row(
            children: <Widget>[
              Container(
                margin: const EdgeInsets.fromLTRB(10.0, 4.0, 5.0, 0.0),
                child: Text(
                  "标题：",
                  style: new TextStyle(fontSize: 15.0, color: Colors.black),
                ),
              ),
              Expanded(
                child: new TextField(
                  maxLines: 1,
                  autofocus: false,
                  decoration: InputDecoration(border: InputBorder.none),
                ),
              )
            ],
          ),
          Container(
            child: new Divider(
              height: 3.0,
              color: Colors.black26,
            ),
            margin: const EdgeInsets.fromLTRB(0, 5, 0, 5),
          ),
          Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Container(
                margin: const EdgeInsets.fromLTRB(10.0, 10.0, 5.0, 0.0),
                child: Text(
                  "详情：",
                  style: new TextStyle(fontSize: 15.0, color: Colors.black),
                ),
              ),
              Expanded(
                child: new TextField(
                  autofocus: false,
                  decoration: InputDecoration(border: InputBorder.none),
                  maxLines: 8,
                ),
              )
            ],
          ),
          Container(
            child: new Divider(
              height: 3.0,
              color: Colors.black26,
            ),
            margin: const EdgeInsets.fromLTRB(0, 5, 0, 5),
          ),
          Row(
            children: <Widget>[
              Container(
                margin: const EdgeInsets.fromLTRB(10.0, 4.0, 5.0, 6.0),
                child: Text(
                  "优先级：",
                  style: new TextStyle(fontSize: 15.0, color: Colors.deepOrangeAccent),
                ),
              ),
              Radio(
                groupValue: this.radio,
                activeColor: Colors.blue,
                value: '一般',
                onChanged: (String val) {
                  // val 与 value 的类型对应
                  this.setState(() {
                    this.radio = val; // aaa
                  });
                },
              ),
              Text("一般", style: new TextStyle(fontSize: 12.0, color: Colors.grey)),
              Container(
                margin: EdgeInsets.fromLTRB(3, 0, 3, 0),
              ),
              Radio(
                groupValue: this.radio,
                activeColor: Colors.blue,
                value: '重要',
                onChanged: (String val) {
                  // val 与 value 的类型对应
                  this.setState(() {
                    this.radio = val; // aaa
                  });
                },
              ),
              Text("重要", style: new TextStyle(fontSize: 12.0, color: Colors.black87)),
            ],
          ),
          Container(
            child: new Divider(
              height: 3.0,
              color: Colors.black26,
            ),
            margin: const EdgeInsets.fromLTRB(0, 5, 0, 5),
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              Container(
                margin: const EdgeInsets.fromLTRB(10.0, 0, 5.0, 2.0),
                child: Text(
                  "日期：",
                  style: new TextStyle(fontSize: 15.0, color: Colors.deepOrangeAccent),
                ),
              ),
              Expanded(
                child: new Text(
                  this.time,
                  style: new TextStyle(fontSize: 13, color: Colors.black),
                ),
              ),
              IconButton(
                  icon: Icon(Icons.keyboard_arrow_right,color: Colors.grey),
                  onPressed: openDataSel)
            ],
          ),
          Container(
            child: new Divider(
              height: 3.0,
              color: Colors.black26,
            ),
            margin: const EdgeInsets.fromLTRB(0, 5, 0, 5),
          ),
          new Expanded(
            child: Text(""),
            flex: 1,
          ),
          Container(
            margin: EdgeInsets.fromLTRB(20, 0, 20, 32),
            child: MaterialButton(
              key: ValueKey("text"),
              child: Text("保存",style: TextStyle(fontSize: 14,color: Colors.white)),
              onHighlightChanged: (bool b) {
                print("onHighlightChanged");
              },
              onPressed: () {
                print("onPressed");
              },
              textTheme: ButtonTextTheme.normal,
              textColor: Colors.white,
              disabledTextColor: Colors.white,
              color: Colors.lightBlueAccent,
              disabledColor: Colors.grey,
              highlightColor: Colors.grey,
              // 按下的背景色

              splashColor: Colors.lightBlue,
              // 水波纹颜色

              colorBrightness: Brightness.light,
              // 主题
              elevation: 10,
              highlightElevation: 10,
              disabledElevation: 10,
              padding: EdgeInsets.all(5),
//       MaterialButton shape 子类才起效
              shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.all(Radius.circular(10)),
                  side: BorderSide(
                      color: Color(0xFFFFFFFF),
                      style: BorderStyle.solid,
                      width: 2)),
              clipBehavior: Clip.antiAlias,
              materialTapTargetSize: MaterialTapTargetSize.padded,
              animationDuration: Duration(seconds: 1),
              height: 39,
              minWidth: 400,
            ),
          )
        ],
      ),
    );
  }

  onBack() {
//    Navigator.pop(context);
  }

  void _textFieldChanged(String str) {
    print(str);
  }

  Widget getMaterialButton(BuildContext context) {
    return MaterialButton(
      key: ValueKey("text"),
      child: Text("MaterialButton"),
      onPressed: pressedBtn(context),
      onHighlightChanged: onHighlightChanged(context),
      textTheme: ButtonTextTheme.normal,
      textColor: Colors.blue,
      disabledTextColor: Colors.red,
      color: Color(0xFF82B1FF),
      disabledColor: Colors.grey,
      highlightColor: Colors.grey,
      // 按下的背景色
      splashColor: Colors.green,
      // 水波纹颜色
      colorBrightness: Brightness.light,
      // 主题
      elevation: 10,
      highlightElevation: 10,
      disabledElevation: 10,
      padding: EdgeInsets.all(10),
//       MaterialButton shape 子类才起效
      shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.all(Radius.circular(20)),
          side: BorderSide(
              color: Color(0xFFFFFFFF), style: BorderStyle.solid, width: 2)),
      clipBehavior: Clip.antiAlias,
      materialTapTargetSize: MaterialTapTargetSize.padded,
      animationDuration: Duration(seconds: 1),
      minWidth: 200,
      height: 50,
    );
  }

  void openDataSel() {
    // 调用函数打开
    showDatePicker(
      context: context,
      initialDate: new DateTime.now(),
      firstDate: new DateTime.now().subtract(new Duration(days: 30)), // 减 30 天
      lastDate: new DateTime.now().add(new Duration(days: 30)), // 加 30 天
    ).then((DateTime val) {
      setState(() {
        time = DateUtil.formatDateTime(
            val.toString(), DateFormat.YEAR_MONTH_DAY, "-", ":");
      });
      print(time); // 2018-07-12 00:00:00.000
    }).catchError((err) {
      print(err);
    });
  }

  pressedBtn(BuildContext context) {
    print("111111");
  }

  onHighlightChanged(BuildContext context) {
    print("22222");
  }
}
